/*
 * @Author: zxc
 * @Date: 2020-08-01 11:42:42
 * @LastEditTime: 2020-08-02 19:07:01
 * @LastEditors: zxc
 * @Description: 泛型
 */ 
interface ValueWithLength{
  length:number
}
// 泛型约束
type GetArray = <T extends ValueWithLength>(x:T,times:number) => T[]
const getArray:GetArray = <T>(arg1:T,times: number):T[] => {
  return new Array(times).fill(arg1)
}

getArray([1,2],3).map(el => el.toString())


// 在泛型约束中使用泛型变量

type GetPropsValue = <T,K extends keyof T>(objs:T,keys:K) => any
const getPropsValues:GetPropsValue = <T,K extends keyof T>(objs:T,keys:K):any => {
  return objs[keys]
}
let obj = {
  a:'a',
  b:'b'
}
getPropsValues(obj,'a')
getPropsValues(obj,'b')
// getPropsValues(obj,'d')